
import { CoordTRFUtil } from "../../common/tools/coordtool";
import textinfo from "../../common/struct/basestruct/textinfo";
import utilfuncs from "../../common/tools/utilfuncs";
var funcs = utilfuncs.UtilFuncs;

import { LGXEnums } from "../../common/sysenum";

import { GlobalVar } from "../../common/globalvar";
import { CommonSvc } from "../../service/commonsvc";

class GetDataSvc {
    constructor(dataManger) {
        this.dataManger = dataManger;
    }
    getMapSelInfo(mosScreenPos) {
        var mapInfo = this.dataManger.getMapViewInfo();
        var worldPt = CoordTRFUtil.screen2world(mosScreenPos, mapInfo);
        var curentGraph = this.dataManger.getCurentGraph();
        var gid = 0;
        var rid = "";
        var name = "";
        var type = 0;
        var sx = mosScreenPos.x;
        var sy = mosScreenPos.y;
        var wx = worldPt.x;
        var wy = worldPt.y;
        var enmmType = "";
        if (curentGraph) {
            gid = curentGraph.m_gid;
            rid = curentGraph.m_rid;
            name = curentGraph.getName();
            type = curentGraph.getType();
            enmmType = curentGraph.m_graphType;
        }
        var scaling = this.dataManger.getScaling();
        return { gid, rid, name, type, sx, sy, wx, wy, enmmType, scaling };
    }

    getGraphInfo(type, gid) {
        var info = null;
        if (gid == 0) {
            var curentGraph = this.dataManger.getCurentGraph();
            if (curentGraph) {
                info = curentGraph.toInfo();
            }
        }
        else {
            var curentGraph = this.dataManger.findGraph(gid);
            if (curentGraph) {
                info = curentGraph.toInfo();
            }
        }
        return info;
    }

    getCoordDatas(gid) {
        let graph = null
        if (gid == 0) {
            graph = this.dataManger.getCurentGraph();
        }
        else {
            graph = this.dataManger.findGraph(gid);
        }
        var coordInfo = null;
        if (graph) {
            coordInfo = graph.getCoordInfo();
        }
        return coordInfo;
    }

    getLineDefDatas(gid) {
        let graph = this.getGraph(gid);
        var dataInfo = null;
        if (graph && (funcs.isBaseUnit(graph.getType()) || graph.m_graphType == LGXEnums.LGXGraphType.Path_type)) {
            dataInfo = graph.getLineInfoDesc();
        }
        return dataInfo;
    }

    getFillDefDatas(gid) {
        let graph = this.getGraph(gid);
        var dataInfo = null;
        if (graph && (funcs.isBaseUnit(graph.getType()) || graph.m_graphType == LGXEnums.LGXGraphType.Path_type)) {
            dataInfo = graph.getFillDefInfo();
        }
        return dataInfo;
    }

    getExtDatas(gid) {
        let graph = this.getGraph(gid);
        var dataInfo = null;
        if (graph) {
            dataInfo = graph.getExtDatas();
        }
        return dataInfo;
    }

    getGraph(gid) {
        let graph = null
        if (gid == 0) {
            graph = this.dataManger.getCurentGraph();
        }
        else {
            graph = this.dataManger.findGraph(gid);
        }
        return graph;
    }

    getNewTextInfo() {
        let newInfo = new textinfo.TextInfo();
        return newInfo;
    }

    getCanvasBackColor() {
        let mapViewInfo = this.dataManger.getMapViewInfo();
        return mapViewInfo.backColor;
    }



    getAttachLabel(gid) {
        let txtInfo = null;
        let destGraph = this.getGraph(gid);
        if (destGraph) {
            let labelGraph = destGraph.getLabel();
            if (labelGraph) {
                txtInfo = labelGraph.toInfo();
            }
        }
        return txtInfo;
    }

    getConfigValue(cfgName) {
        let result = null;
        switch (cfgName) {
            case 'backcolor':
                result = this.getBackColorCfg();
                break;

            case 'grid':
                result = this.getGridCfg();
                break;

            case 'disLineWidth':
                result = this.getLineWidthCfg();
                break;

        }
        return result;
    }

    getBackColorCfg() {
        return this.getCanvasBackColor().toHexString();
    }

    getGridCfg() {
        let mapinfo = this.dataManger.getMapViewInfo();
        let dis = mapinfo.getDisGrid();
        let span = mapinfo.getGridSpan();
        let color = mapinfo.getGridColor();
        let grid = {dis,span,color};
        return grid;
    }



    getLineWidthCfg() {
        let mapinfo = this.dataManger.getMapViewInfo();
        return mapinfo.getLineWidthShow();
    }

    getMapValidSize(){
        let allGraph = this.dataManger.getAllVisibleGraphs();
        let rect = CommonSvc.calGraphsZone(allGraph);
        let width = rect.width();
        let height = rect.height();
        return {width,height};
    }

}

export default { GetDataSvc }